<?php
defined('IN_IXDCW') or exit('Access Denied');
/**
 * 文件上传的代码
 * @param $replace
 * @param $source
 * @param $preview
 * @return mixed
 */
function xd_uploadify($replace, $source, $preview){
	$html = <<<PHPDOC
<script src="file/script/uploadify/jquery.uploadify-3.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="file/script/uploadify/uploadify.css" />
<input type="file" name="uploadify" id="__REPLACE__" />
<script>
$(function() {
	if($('#__PREVIEW__').val()) {
		$('#uploadify___PREVIEW__').html($('<img />').attr('src', $('#__PREVIEW__').val()));
	}
	$('#__REPLACE__').uploadify({
		'swf'     : 'file/script/uploadify/uploadify.swf',
		'uploader': 'api/auto/upload.php',
		'method'  : 'post',
		'multi'   : false,
		'formData': {
			'source':'__SOURCE__'
		},
		'buttonText' : '上传',
		'width' : 60,
		'height' : 20,
		'fileTypeDesc' : '图像文件',
		'fileTypeExts' : '*.gif; *.jpg; *.png; *.jpeg',
		'onUploadSuccess':function (file, data, response) {
			var result = JSON.parse(data);
			if (result.status) {
				$('#__PREVIEW__').val(result.file);
				$('#uploadify___PREVIEW__').html($('<img />').attr('src', result.file));
			} else {
				alert(result.reason);
			}
		}
	});
});
</script>
PHPDOC;
	return str_replace(array('__REPLACE__', '__SOURCE__', '__PREVIEW__'), array($replace, $source, $preview), $html);
}












?>